Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Add WebSockets Router #6941

Draft
wants to merge 48 commits into
base: develop
Choose a base branch
from
Draft

Conversation

deeleeramone
Copy link
Contributor

@deeleeramone deeleeramone commented Nov 8, 2024

Just putting this out here in draft form so people can try it out and critique the implementation. Many details to follow, but the general gist is to be able to interact with, and control, multiple connections from the main app or API.

See the README.md file for more details than you probably want...

Quick explanation of how to install and use:

  • From the openbb_platform folder, run: dev_install.py -e
  • Rebuild - openbb-build
  • Create a new connection (as of right now, just Tiingo and FMP, but Polygon and Intrinio to follow)
obb.websockets.create_connection(provider="fmp", name="fmp_crypto", asset_type="crypto", symbol="btcusd")

This will create a new instance of the client, with the "name" being what is used to interact with from the router endpoints.

By default, a temp file hosts a SQL database, with a size limit of 300 rows, which will be discarded on exit, along with any open connections/threads. A broadcast server is also started on localhost using port 6666.

In a separate terminal, activate the obb environment and import the listener helper.

from openbb_websockets.listen import listen

listen("ws://127.0.0.1:6666")

You could have as many connections to the broadcast server as conditions allow.

Screenshot 2024-11-07 at 5 31 14 PM

You can get the validated results at any time from the main app with get_results

obb.websockets.get_results("fmp_crypto").to_df()

Screenshot 2024-11-07 at 5 33 47 PM

Subscribe and Unsubscribe events happen without interrupting the active stream, and the broadcast can be terminated without killing the provider connection. Providers will let you subscribe to any string, regardless of being a valid symbol, so "success" doesn't always mean that it will yield results. Some providers will allow subscribing to all, * . Tiingo with "all crypto" yields about 100-200 messages per second.

obb.websockets.subscribe("fmp_crypto", symbol="ethusd,solusd")

Screenshot 2024-11-07 at 5 43 44 PM

This is the contents of the router extension, "get_client" is excluded from the API.

In [4]: obb.websockets
Out[4]: 
/websockets
    clear_results
    create_connection
    get_client
    get_client_status
    get_results
    kill
    restart_connection
    start_broadcasting
    stop_broadcasting
    stop_connection
    subscribe
    unsubscribe
  1. Why?:

    • To provide a way to work with various websocket connections in a non-blocking pattern.
  2. What?:

  3. Impact:

  4. Testing Done:

  5. Reviewer Notes (optional):

  6. Any other information (optional)

@github-actions github-actions bot added enhancement Enhancement platform OpenBB Platform v4 PRs for v4 labels Nov 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Enhancement platform OpenBB Platform v4 PRs for v4
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant